<template>
  <div class="address-box">
    <van-address-list
      v-if="list.length>=1"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
    <template v-else>
      <div class="lastbtn">
        暂无数据
      </div>
      <van-button
        block
        round
        type="info"
        @click="$router.push({
        path: '/address-edit',
        query: {
          type: 'add'
        }
      })"
      >去设置地址
      </van-button>
    </template>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: []
    }
  },
  created() {
    this.getAdress()
  },
  methods: {
    onAdd() {
      this.$router.push({
        path: '/address-edit',
        query: {
          type: 'add'
        }
      })
    },
    onEdit(item, index) {
      this.$router.push({
        path: '/address-edit',
        query: {
          type: 'edit',
          id: item.id
        }
      })
    },

    async getAdress() {
      const adress = JSON.parse(localStorage.adress)
      this.list = adress
    }
  }
}
</script>

<style lang="scss">
.address-box {
  height: 100vh;

  .van-radio__icon {
    display: none;
  }

  .lastbtn {
    text-align: center;
    margin: 50px 0;
  }

  .van-address-list {
    background: #f7f8fa;
  }
}
</style>
